﻿import QtQuick 2.12
import QtQuick.Templates 2.12
import QtGraphicalEffects 1.14


// 气泡式弹窗
Item {

    id: root

    property string title: "这是一个气泡弹窗"

    property bool acceptedButton: true
    property bool rejectedButton: true

    anchors.fill: parent
    property int trigger: 0     // 0:悬浮时显示 1:点击时显示 2:手动控制显示

    property real posiX: root.width / 2
    property real posiY: root.height + 5*dp

    property bool showPopup: false

    signal accepted()
    signal rejected()

    MouseArea{
        anchors.fill: root
//        propagateComposedEvents: true

        cursorShape: "PointingHandCursor"

        onClicked: {
            popup.visible = !popup.visible
            mouse.accepted = false
        }

    }

    Popup{

        id: popup

        x: posiX
        y: posiY

        background: Rectangle{

            height: 100*dp
            width: 260*dp

            radius: 3*dp

            CustomImage{
                height: 16*dp; width: 16*dp
                x: 10*dp; y: 12*dp
                source: "qrc:/picture/warning_y.png"
                mipmap: true
            }

            Text{
                height: 30*dp; width: parent.width-40*dp
                x: 30*dp; y: 10*dp
                text: title
                wrapMode: Text.WrapAnywhere
                font.pixelSize: config.fontsize
            }

            // 按钮
            Item{
                x: 10*dp; y: 60*dp
                width: parent.width - 20*dp
                height: 30*dp
                CustomButton{
                    height: 30*dp; width: 60*dp
                    defaultMode1: true
                    title: "确定"
                    visible: acceptedButton
                    x: parent.width - width
                    onClicked: {
                        popup.visible = false
                        root.accepted()
                    }
                }CustomButton{
                    height: 30*dp; width: 60*dp
                    button_color: "#EEEEEE"
                    visible: rejectedButton
                    title: "取消"
                    x: parent.width - width - (acceptedButton ? 70*dp : 0)
                    onClicked: {
                        popup.visible = false
                        root.rejected()
                    }
                }
            }

            layer.enabled: true
            layer.effect: DropShadow {
                radius: 21*dp
                samples: 43
                transparentBorder: true
                color: "#2D666666"
            }
        }

    }


}
